#! /bin/sh -e
# $Id: postinst 3292 2007-05-21 14:02:05Z jeff $
# $Author: jeff $
#
# Post-install directives for FreeMED package

# Patch PHP ini file to have more than 8M per process
if [ -f /etc/php4/apache/php.ini ]; do
	perl -pi -e "s|8M|64M|;" /etc/php4/apache/php.ini
fi
if [ -f /etc/php4/apache2/php.ini ]; do
	perl -pi -e "s|8M|64M|;" /etc/php4/apache2/php.ini
fi

# Apache user has to own freemed
echo -n "Updating ownership of freemed to webserver user ... "
chown -Rf www-data.www-data /usr/share/freemed 
echo "[done]"

# Change writeable permissions for data/, img/store, etc
echo -n "Updating permissions ... "
chmod -Rf a+w /usr/share/freemed/data/{cache,backup,store}
echo "[done]"

# Attempt to create freemed mysql database ... will have no password if
# it has just been installed. Do not run if there is already a freemed
# version installed.
if [ ! -d /var/lib/mysql/freemed ]; then \ 
	echo "Attempting to create freemed database (enter password, or enter if none) ... "; \
	mysqladmin -u root -p create freemed 2>&1; \
	echo "[done]"; \
fi

# Restart apache ...
echo "Restarting apache to reload configuration files ... "
if [ -f /etc/init.d/apache ]; then \
	/etc/init.d/apache restart; \
fi
if [ -f /etc/init.d/apache-ssl ]; then \
	/etc/init.d/apache-ssl restart; \
fi
if [ -f /etc/init.d/apache2 ]; then \
	/etc/init.d/apache2 restart; \
fi

#DEBHELPER#

exit 0
